import random
from Random_module import *

class Role:
    def __init__(self, name, hp,hp_true, attack_name,attack,energy,skill_name,skill_state,skill,potion_state,grade):
        self.name = name                    #职业
        self.hp = hp                        #最大生命
        self.hp_true = hp_true              #真实血量        
        self.attack_name = attack_name      #普攻名称
        self.attack = attack                #普攻伤害
        self.energy =energy                 #蓝条
        self.skill_name = skill_name        #技能名
        self.skill_state = skill_state      #技能状态，是否存在       
        self.skill = skill                  #技能伤害
        self.potion_state = potion_state    #药水数量
        self.grade = grade                  #角色等级    
    """
    根据输入的操作符，执行相应的操作
    :param op_num:0表示攻击,1表示使用技能,2表示回蓝,3表示使用药水
    :param attack_obj: 攻击的对象
    """

    def alive(self):#判断是否死亡
        return self.hp_true > 0
    
    def recover(self, value):
        self.hp_true += value
        if self.hp_true > self.hp:
            self.hp_true = self.hp

    def att_ack(self, other):                       #选择0，进行攻击
        if random.random() < 0.01:
            damage = self.attack * 2
            print(f"暴击！{self.name}对{other.name}使用了{self.attack_name},造成了{damage}点伤害")
        else:
            damage = self.attack
            print(f"{self.name}对{other.name}使用了{self.attack_name},造成了{damage}点伤害")
        other.hp_true -= damage
    def ski_ll(self,other):                         #选择1,使用技能
        if self.skill_state == "获得":
            if other.energy - 25 >= 0 :
                if random.random() < 0.01:
                    damage = self.skill * 2
                    print(f"暴击！{self.name}对{other.name}使用了{self.skill_name},造成了{damage}点伤害")
                else:
                    damage = self.skill
                    print(f"{self.name}对{other.name}使用了{self.skill_name},造成了{damage}点伤害")
                other.hp_true -= damage
                other.energy -= 25
            else:
                print("无效选择，蓝量不够")        
        else:
            print("无效选择，你未获得技能")
    def sleep(self):                                #选择2，进行回蓝
        self.energy+=20
    def potion(self):                               #选择3，使用药水回血
        if self.potion_state == 0 :
            print("无效选择，你无药水")
        else:
            self.potion_state -= 1
            self.hp_true += 100
            print(f"{self.name} 使用了药水，恢复了 100 点生命值。")
 
      

def game():
    print("欢迎来到游戏！")
    print("请输入你的角色名")
    role_name=input("> ")
    print("请选择你的角色：")    
    print("1. 法师")
    print("2. 战士")
    select = input("> ")                   #输入选择
    if select == "1" :
        print("请选择你的元素：")
        print("1. 火")
        print("2. 冰")
        print("3. 雷")
        select = input("> ")
        if select == "1":
            role = Role(role_name,140,140,"火球术",50,100,"火焰箭","未获得",110,0,1)
        elif select == "2":
            role = Role(role_name,180,180,"冰冻术",30,100,"冰锥术","未获得",90,0,1)
        elif select == "3":
            role = Role(role_name,130,130,"雷电术",60,100,"闪电箭","未获得",120,0,1)
    elif select == "2" :
        print("请选择你的风格：")
        print("1.坦克")
        print("2. 狂战士")
        print("3. 刺客")
        select = input("> ")                #输入选择
        if select == "1":
            role = Role(role_name,240,240,"盾击",25,100,"钢铁打击","未获得",70,0,1)
        elif select == "2":
            role = Role(role_name,160,160,"猛击",50,100,"猛击","未获得",110,0,1)
        elif select == "3":
            role = Role(role_name,140,140,"快刀斩",60,100,"暗杀","未获得",120,0,1)
    else:
        print("无效的选择。")
        return
    
    boss1=Role("杨样",160,160,"叫！(手可以软，但嘴必须硬！！！)",10,100,"我超勇的","获得",40,0,1)
    boss2=Role("琛",200,200,"いやです!!!(不要!)", 20,100,"我没有惹任何人！！！","获得",90,0,2)
    boss3=Role("祁",500,500,"渣渣",45,100,"没实力啊老弟","获得",500,0,3)
    boss= [boss1,boss2,boss3]
    for i in range(3):
        print("")
        print("")
        print(f"====================== 第 {i+1} 关 ====================== ")
        while role.alive() and boss[i].alive():
            print("")
            print(f"{role.name}：等级 {role.grade} 生命值 {role.hp_true}/{role.hp}   魔法值 {role.energy}   技能状态:{role.skill_state}   药水数量:{role.potion_state}")
            print(f"{boss[i].name}：生命值 {boss[i].hp_true}/{boss[i].hp}")
            print("1. 攻击")
            print("2. 施法")
            print("3. 恢复魔法值")
            print("4. 使用药水")
            select = input(">> ")
            if select == "1":
                role.att_ack(boss[i])
            elif select == "2":
                role.ski_ll(boss[i])
            elif select == "3":
                role.sleep()
                print(f"{role.name} 恢复了 20 点魔法值。")
            elif select == "4":
                role.potion()
            else:
                print("无效的选择。")
                continue
            if boss[i].hp_true <= boss[i].hp*0.5 and boss[i].skill_state == "获得":#判断怪的血量是否大于生命值的一半，大于则普攻，小于则使用技能，技能只能使用一次
                boss[i].ski_ll(role)
                boss[i].skill_state = "未获得"
            else:
                boss[i].att_ack(role)        
        if role.alive():
            print("")
            print(f"========== {role.name} 获得胜利！ 等级加1 ==========")
            print("")
            if i == 0:
                role.hp += role.hp // 10 * 2            #升级，增加%20的生命
                role.potion_state += 3                  #获得三瓶回血药水
                role.recover(role.hp // 10)             #恢复10%的血量
                role.grade += 1                         #等级加一
                print(f"{role.name}升级，当前等级为{role.grade}")
                print(f"{role.name} 发现了三瓶回血药水,并恢复了一些生命值。")
            elif i == 1:
                role.recover(role.hp // 10)             #恢复10%的血量
                role.hp += role.hp // 10 * 2            #升级，增加%20的生命
                role.grade += 1                         #等级加一
                role.skill_state = "获得"               #获得技能
                print(f"{role.name} 学会了新的法术：{role.skill_name},并恢复了一些生命值。")
        else:
            print(f"{boss[i].name} 获胜!")
            return
    print("恭喜你获得了游戏的胜利！")            
game()